package com.sikaryofficial.backend.controller.information;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.domain.dto.req.information.TopicListReq;
import com.sikaryofficial.backend.domain.dto.resp.information.TopicBackendDTO;
import com.sikaryofficial.backend.domain.dto.resp.information.TopicDTO;
import com.sikaryofficial.backend.manager.information.TopicManager;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * topic服务
 *
 * @author qinjinyuan
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/article/topic")
@Api(tags = "资讯-topic服务")
@SuppressWarnings(value = "unchecked")
public class TopicController extends BaseController {
    @Autowired
    private TopicManager topicManager;

    /**
     * 查询topic列表
     */
    @ApiOperation("查询topic分页列表")
    @PostMapping("/listPage")
    public PageResult<TopicDTO> listPage( @Validated @RequestBody TopicListReq req) {
        IPage<TopicDTO> page = topicManager.listPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 后台管理端查询topic列表
     */
    @ApiOperation("管理端topic分页列表")
    @PostMapping("/backend/listPage")
    public PageResult<TopicBackendDTO> listBackendPage(@Validated @RequestBody TopicListReq req) {
        IPage<TopicBackendDTO> page = topicManager.listBackendPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

}
